package userInterface;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class BasicUI 
	extends MIDlet 
	implements CommandListener 
{
	private Display mDisplay;
	private Command mExitCommand, mAlertCommand;
	private TextBox mTextBox;
	
	public void startApp() {
		if(mTextBox == null) {
			mTextBox = new TextBox("TextBox example", 
					"Choose 'Show Alert!' to see an alert",
					128, TextField.UNEDITABLE);
			mTextBox.setTicker(new Ticker("Un Ticker este folosit pentru " +
					"a afisa texte foarte lungi" +
					"in bara de sus a aplicatiei."));
			mExitCommand = new Command("Exit", Command.EXIT, 0);
			mAlertCommand = new Command("Show alert", Command.SCREEN, 0);
			mTextBox.addCommand(mExitCommand);
			mTextBox.addCommand(mAlertCommand);
			mTextBox.setCommandListener(this);
			mDisplay = Display.getDisplay(this);
		}
		mDisplay.setCurrent(mTextBox);
	}
	public void pauseApp() {}
	public void destroyApp(boolean unconditional) {}
	public void commandAction(Command c, Displayable d) {
		if (c == mExitCommand) {
			destroyApp(true);
			notifyDestroyed();
		} else if (c == mAlertCommand) {
			Image i = null;
			try {
				i = Image.createImage("/ubuntu.png");
			} 
			catch (java.io.IOException ioe) {} 
			catch (Exception e) {}
			Alert a = new Alert("This is the title", "This is the message",
					i, AlertType.INFO);
			a.setTimeout(5000);
			mDisplay.setCurrent(a, mTextBox);
		}
	}
}
